package com.uubx.service.impl;

import com.uubx.mapper.ProtocolsMapper;
import com.uubx.pojo.Protocols;
import com.uubx.service.ProtocolsService;
import com.uubx.vo.BatchVo;
import com.uubx.vo.ProtocolsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class ProtocolsServiceImpl implements ProtocolsService {

@Autowired
private ProtocolsMapper protocolsMapper;
    @Override
    public List<Map> queryAllProtocols(ProtocolsVo protocolsVo) {
        //List<Map> mapList = protocolsMapper.queryAllProtocols(protocolsVo);

        return protocolsMapper.queryAllProtocols(protocolsVo);
    }

    @Override
    public void BatchDeleteProtocols(BatchVo batchVo) {
        protocolsMapper.BatchDeleteProtocols(batchVo);
    }


    @Override
    public void saveProtocols(Protocols protocols) {
        protocolsMapper.saveProtocols(protocols);

    }

    @Override
    public Protocols queryProtocolsById(Long id) {
        //Protocols protocols = protocolsMapper.queryProtocolsById(id);
        return protocolsMapper.queryProtocolsById(id);
    }

    @Override
    public void updateProtocols(Protocols protocols) {
        //更新协议的上下架状态 值：是、否。若上架状态为是：则设置下架时间为null，反之类似，时间会由前端携带过来
        if (protocols.getPuttime()!=null){
            protocols.setRemovetime(null);
            protocolsMapper.updateProtocols(protocols);
        }else if (protocols.getRemovetime()!=null){
            protocols.setPuttime(null);
            protocolsMapper.updateProtocols(protocols);
        }else {
            protocolsMapper.updateProtocols(protocols);
        }

    }

    @Override
    public void deleteProtocolsById(Long id) {
        protocolsMapper.deleteProtocolsById(id);
 }

    @Override
    public Long queryProtocolsCount() {
       // Long aLong = protocolsMapper.queryProtocolsCount();
        return protocolsMapper.queryProtocolsCount();
    }
}
